<template>
	<scroll-view scroll-y="true">
			<myHead :title="title"></myHead>
		<!-- 头部 -->
		<view class="list-head" :style="{'background-image':'url('+ playlist.coverImgUrl +')'}">
			<view class="list-head-img">
				<image :src="playlist.coverImgUrl" mode=""></image>
				<text>{{ playlist.playCount | formatCount }}</text>
			</view>
			<view class="list-head-text">
				<view>{{ playlist.name }}</view>
				<view>
					<image :src="playlist.creator.avatarUrl" mode=""></image>
					<text>{{ playlist.creator.nickname }}</text>
				</view>
				<view>{{ playlist.description }}</view>
			</view>
		</view>

		<!-- 音乐列表 -->
		<view class="list-music">
			<view v-show="isShow" class="list-music-title">
				<view class="count-icon">
					<image src="/static/play-ico.png" alt="" class="icon" />
				</view>
				<text>播放全部</text>
				<text>(共{{ playlist.trackCount }}首)</text>
			</view>

			<view class="list-music-item" v-for="(item, index) in playlist.tracks" :key="item.id"
				@tap="goToDetail(item.id)">
				<!-- 序号 -->
				<view class="list-music-index">{{ index + 1 }}</view>
				<!-- 歌曲信息 -->
				<view class="list-music-song">
					<view>{{ item.name }}</view>
					<view>
						<!-- 判断是否独家音频 -->
						<image v-if="privileges[index].flag > 60 && privileges[index].flag < 70" src="/static/dujia.png"
							mode=""></image>
						<!-- 判断是否为无损音质 -->
						<image v-if="privileges[index].maxbr === 999000" src="/static/sq.png" mode=""></image>
						{{ item.ar[0].name }} - {{ item.name }}
					</view>
				</view>
			</view>
		</view>
	</scroll-view>
</template>


<script>
		import myHead from '../../components/myHead/myHead.vue'
	import {
		musicList,songUrl
	} from '../../commom/api.js'
	export default {
		data() {
			return {
				playlist: {
					coverImgUrl: '',
					trackCount: '',
					creator: ''
				},
				privileges: [],
				isShow: false,
				title:""
			}
		},
		// 页面加载时获取音乐列表数据
		onLoad(options) {
			let listId = options.listid;
			musicList(listId).then((res) => {
				if (res.data.code == '200') {
					this.title = res.data.playlist.name
					this.playlist = res.data.playlist
					this.privileges = res.data.privileges
					this.isShow = true
				}
			});

		},
		methods: {
			goToDetail(id) {
				// 在导航到播放器页面前获取歌曲链接并传递给播放器页面
				songUrl(id).then((res) => {
					const url = res.data.data[0].url;
					uni.navigateTo({
						url: '/pages/player/player?songId=' + id
					});
				}).catch((error) => {
					console.error('获取歌曲链接失败', error);
				});
			}
		},
		filters: {
			formatCount(value) {
				if (value >= 10000 && value < 100000000) {
					value /= 10000;
					return value.toFixed(1) + '万';
				} else if (value >= 100000000) {
					value /= 100000000;
					return value.toFixed(1) + '亿';
				} else {
					return value;
				}
			}
		}

	}
</script>

<style>
	.list-music-title {
		display: flex;
		/* 使用 Flex 布局 */
		align-items: center;
		/* 垂直居中对齐 */
	}

	.count-icon {
		width: 50rpx;
		/* 设置图标容器宽度 */
		height: 50rpx;
		/* 设置图标容器高度 */
	}

	.icon {
		width: 100%;
		/* 图标宽度 */
		height: 100%;
		/* 图标高度 */
	}

	.list-head {
		display: flex;
		padding: 70rpx 0rpx 50rpx 10rpx;
	}

	.flexbg {
		z-index: -1;
		width: 100%;
		height: 100vh;
		position: fixed;
		left: 0;
		top: 0;
		background-image: url(/static/logo.jpg);
		background-size: cover;
		background-position: center 0;
		/* 背景模糊以及毛边框特效 */
		filter: blur(10px);
		transform: scale(1.2);

	}

	.list-head-img {
		width: 264rpx;
		height: 264rpx;
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		margin-left: 26rpx;
		margin-right: 42rpx;
	}

	.list-head-img image {
		width: 100%;
		height: 100%;
	}

	.list-head-img text {
		position: absolute;
		right: 8rpx;
		top: 8rpx;
		color: white;
		font-size: 26rpx;
	}

	.list-head-text {
		flex: 1;
		color: #f0f2f7;
	}

	.list-head-text view:nth-child(1) {
		color: white;
		font-size: 34rpx;
	}

	.list-head-text view:nth-child(2) {
		display: flex;
		margin: 20rpx 0;
	}

	.list-head-text view:nth-child(2) image {
		width: 54rpx;
		height: 54rpx;
		border-radius: 50%;
		margin-right: 34rpx;
		font-size: 24rpx;
		align-items: center;
	}

	.list-head-text view:nth-child(3) {
		line-height: 34rpx;
		font-size: 20rpx;
	}


	.list-music {}

	.list-music-title {
		height: 58rpx;
		line-height: 58rpx;
		margin: 30rpx 30rpx 70rpx 30rpx;
	}

	.list-music-title .count-icon {
		display: ;
	}

	.list-music-title text:nth-child(1) {
		font-size: 58rpx;
	}

	.list-music-title text:nth-child(2) {
		font-size: 34rpx;
		margin: 0 10rpx 0 25rpx;
	}

	.list-music-title text:nth-child(3) {
		font-size: 28rpx;
		color: #b2b2b2;
	}


	.list-music-item {
		display: flex;
		margin: 0 25rpx 70rpx 44rpx;
		align-items: center;

	}

	.list-music-index {
		width: 60rpx;
		font-size: 35rpx;
		color: #979797;
	}

	.list-music-song {
		flex: 1;
		line-height: 40rpx;
	}

	.list-music-song view:nth-child(1) {
		font-size: 35rpx;
		width: 70vw;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.list-music-song view:nth-child(2) {
		font-size: 25rpx;
		color: #a2a2a2;
		width: 70vw;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.list-music-song image {
		width: 34rpx;
		height: 22rpx;
		margin-right: 10rpx;
	}

	.list-music-item text {
		font-size: 50rpx;
		color: #c8c8c8;
	}
</style>